import requests
import datetime

start_date = '2024-01-01'
gu_piao_no = '002851'
today = datetime.date.today()
# end_date = today
end_date = '2024-04-30'
print(today)
order = 1
jiaoyisuo = "XSHE"
url = f"https://tsanghi.com/api/fin/stock/{jiaoyisuo}/daily?token=6ec29b7b9e2344de99a6fa8bde6bdc2b&ticker={gu_piao_no}&fmt=csv&start_date={start_date}&end_date={end_date}&order=1"
print(url)
import requests


# 发起请求
response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 保存为文件
    with open(f"{gu_piao_no}_{start_date}_{end_date}.csv", "wb") as f:
        f.write(response.content)
    print("CSV 文件保存成功！")
else:
    print(f"请求失败，状态码：{response.status_code}")
